﻿using Microsoft.Extensions.DependencyInjection;
using PmSoft;

namespace Modules.Logs;


/// <summary>
/// 各应用log4net调试日志服务
/// </summary>
[UseDI(ServiceLifetime.Scoped)]
public class Log4netDebugService
{
    private readonly Log4netDebugRepository log4netDebugRepository;

    public Log4netDebugService(Log4netDebugRepository log4netDebugRepository)
    {
        this.log4netDebugRepository=log4netDebugRepository;
    }

    /// <summary>
    /// 各应用log4net调试日志表单详情
    /// </summary>
    /// <param name="id">主键</param>
    /// <returns></returns>
    public Log4netDebug? Get(int id)
    {
        return log4netDebugRepository.Get(id);
    }

    /// <summary>
    /// 批量删除，根据id
    /// </summary>
    /// <param name="ids">id的集合</param>
    public void Deleted(IEnumerable<int> ids)
    {
        foreach (int id in ids)
        {
            Delete(id);
        }
    }

    /// <summary>
    /// 单个删除
    /// </summary>
    /// <param name="id">主键</param>
    public void Delete(int id)
    {
        log4netDebugRepository.DeleteByEntityId(id);
    }

    /// <summary>
    /// 创建各应用log4net调试日志
    /// </summary>
    /// <param name="entity">实体对象</param>
    public void Create(Log4netDebug entity)
    {
        log4netDebugRepository.Insert(entity);
    }

    /// <summary>
    /// 编辑各应用log4net调试日志
    /// </summary>
    /// <param name="entity">实体对象</param>
    public void Update(Log4netDebug entity)
    {
        log4netDebugRepository.Update(entity);
    }

    /// <summary>
    /// 各应用log4net调试日志分页列表
    /// </summary>
    /// <param name="query">查询参数</param>
    /// <param name="pageIndex">当前页码</param>
    /// <param name="pageSize">每页显示条数</param>
    /// <returns></returns>
    public IPagedList<Log4netDebug> GetLog4netDebugs(Log4netQuery query, int pageIndex, int pageSize)
    {
        return log4netDebugRepository.GetLog4netDebugs(query, pageIndex, pageSize);
    }
}